<template>
  <nav class="navigation">
    <div class="nav-buttons">
      <button 
        v-for="item in navItems" 
        :key="item.name"
        :class="['nav-button', { active: currentRoute === item.route }]"
        @click="navigateTo(item.route)"
        :title="item.title"
      >
        <span class="nav-icon">{{ item.icon }}</span>
        <span class="nav-text">{{ item.title }}</span>
      </button>
      
      <!-- 简化用户信息区域 -->
      <div class="simple-user-section">
        <div class="user-avatar-btn" @click="toggleUserMenu">
          <div class="user-avatar-mini">
            <img src="https://ts1.tc.mm.bing.net/th/id/R-C.f94b9202d33f187002be09f1cf3be3ec?rik=X4t9O3gfB%2fiOAg&riu=http%3a%2f%2fimg.sucaijishi.com%2fuploadfile%2f2023%2f0221%2f20230221013648837.png%3fimageMogr2%2fformat%2fjpg%2fblur%2f1x0%2fquality%2f60&ehk=IhQfM%2f3PYN1uDUJRn7%2f%2bEuIvhjz1tvEZM03WatipHxE%3d&risl=&pid=ImgRaw&r=0" alt="用户头像" />
            <div class="online-indicator"></div>
          </div>
        </div>
        <div v-if="showUserMenu" class="user-menu">
          <button class="logout-btn" @click="logout">退出登录</button>
        </div>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

const currentRoute = computed(() => route.name)
const showUserMenu = ref(false)

const navItems = ref([
  { name: 'home', route: '/', title: '主页', icon: '🏠' },
  { name: 'categories', route: '/categories', title: '分类', icon: '📂' },
  { name: 'summary', route: '/summary', title: '摘要', icon: '📊' },
  { name: 'settings', route: '/settings', title: '设置', icon: '⚙️' }
])

const navigateTo = (routePath) => {
  router.push(routePath)
}

// 切换用户菜单显示
const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value
}

// 退出登录
const logout = () => {
  if (confirm('确定要退出登录吗？')) {
    console.log('用户退出登录')
    // 这里可以添加实际的退出登录逻辑
    showUserMenu.value = false
  }
}

// 点击其他地方关闭菜单
const closeUserMenu = (event) => {
  if (!event.target.closest('.simple-user-section')) {
    showUserMenu.value = false
  }
}

// 添加全局点击事件监听
onMounted(() => {
  document.addEventListener('click', closeUserMenu)
})

onUnmounted(() => {
  document.removeEventListener('click', closeUserMenu)
})
</script>

<style scoped>
.navigation {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  width: 80px;
}

.nav-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 0 20px 20px 0;
  padding: 20px 10px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.nav-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: transparent;
  border: 1px solid #cbd5e1;
  border-radius: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #475569;
  position: relative;
}

.nav-button:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  transform: translateX(5px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.nav-button.active {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border-color: #3b82f6;
  color: white;
  transform: translateX(10px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.nav-button.active::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 30px;
  background: #fff;
  border-radius: 2px;
}

.nav-icon {
  font-size: 24px;
  margin-bottom: 5px;
}

.nav-text {
  font-size: 12px;
  font-weight: 500;
}

/* 简化用户信息区域 */
.simple-user-section {
  position: relative;
  margin: 20px 15px;
  display: flex;
  justify-content: center;
}

.user-avatar-btn {
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.user-avatar-btn:hover {
  transform: scale(1.05);
}

.user-avatar-mini {
  width: 45px;
  height: 45px;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.user-avatar-mini img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.online-indicator {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background: #4CAF50;
  border: 2px solid white;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.user-menu {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  padding: 8px 0;
  min-width: 120px;
  z-index: 1000;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.logout-btn {
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: #ff4757;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  transition: all 0.3s ease;
}

.logout-btn:hover {
  background: rgba(255, 71, 87, 0.1);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@media (max-width: 768px) {
  .navigation {
    width: 60px;
  }
  
  .nav-buttons {
    padding: 15px 5px;
    border-radius: 0 15px 15px 0;
  }
  
  .nav-button {
    width: 50px;
    height: 50px;
  }
  
  .nav-icon {
    font-size: 20px;
  }
  
  .nav-text {
    font-size: 10px;
  }
  
  .user-info-section {
    padding: 10px 5px;
    flex-direction: column;
    text-align: center;
  }
  
  .user-avatar-mini {
    width: 35px;
    height: 35px;
    margin-right: 0;
    margin-bottom: 5px;
  }
  
  .user-name-mini {
    font-size: 10px;
  }
  
  .user-status-mini {
    font-size: 9px;
  }
}
</style>